package routers

import (
	"gitee.com/xuaxu/go-gin/middleware/jwt"
	"gitee.com/xuaxu/go-gin/pkg/export"
	"gitee.com/xuaxu/go-gin/pkg/qrcode"
	"gitee.com/xuaxu/go-gin/pkg/upload"
	"gitee.com/xuaxu/go-gin/routers/api"
	"gitee.com/xuaxu/go-gin/routers/api/v1"
	_ "github.com/EDDYCJY/go-gin-example/docs"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"net/http"
)

// InitRouter initialize routing information
func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	r.StaticFS("/export", http.Dir(export.GetExcelFullPath()))
	r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
	r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))

	r.POST("/auth", api.GetAuth)
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	r.POST("/upload", api.UploadImage)

	apiv1 := r.Group("/api/v1")
	apiv1.Use()
	{
		apiv1.POST("/login", v1.Login)

	}
	apiv1.Use(jwt.JWT())
	{
		//获取标签列表
		apiv1.POST("/get_article", v1.GetArticle)
		apiv1.POST("/sync_article", v1.SyncArticle)
	}

	return r
}
